const fs = require('fs')
const path = require('path')
const notePath = path.join(process.env.HOME, '.znote')

let exist = fs.existsSync(notePath)
if (!exist) {
  fs.mkdirSync(notePath)
}

let configFile = path.join(notePath, 'config.json')
exist = fs.existsSync(configFile)
let config = {
  'NoteRoot': path.join(process.env.HOME, 'znote')
}

if (exist) {
  config = fs.readFileSync(configFile, 'utf-8')
  config = JSON.parse(config)
} else {
  fs.writeFileSync(configFile, JSON.stringify(config))
}

exist = fs.existsSync(config.NoteRoot)
if (!exist) {
  fs.mkdirSync(config.NoteRoot)
}

module.exports = config
